#!/bin/bash

randomNum() {
	if [ $# -eq 1 ];then
		(( rand = $RANDOM*$1/32767 ))
		echo $rand
	else
		echo $RANDOM
	fi
}

completar() {
	formedNumber=""
	if [ $# -eq 2 ];then
		(( max = $2 - 1 ))

		for (( i = $max; i >= 0; i-- ))
		do
			((tenth = 10 ** $i))
			if [ $1 -lt $tenth ];then
				formedNumber=$formedNumber"0"
			else
				formedNumber=$formedNumber"$1"
				break;
			fi
		done
		echo $formedNumber
	else
		echo "maaaaaaaal"
	fi
}

genRegistro() {

	codCentral=CENTRAL
	codCliente=CLIENTE
	codArea=AREA
	zona3G=N
	nroLinea=
	promedio=
	morisidad=
	deuda=
	IUR=N
	INT=N
	ADSL=N
	CABA=N
	GBAOes=N
	GBANor=N
	Country=N
	Delta=N
	Rural=N
	Jub=N
	Res=N
	CF=N
	MO=N
	RI=N
	FechaCorte=20090503



	var=`randomNum 999`
	var=`completar $var 3`
	codCentral=$codCentral$var

	var=`completar $1 3`
	codCliente=$codCliente$var


	var=`randomNum 10`
	var=`completar $var 6`
	codArea=$codArea$var

	var=`randomNum 9999999999`
	var=`completar $var 10`
	nroLinea=$var

	var=`randomNum 9999999999`
	var=`completar $var 10`
	promedio=$var

	var=`randomNum 5`
	morosidad=$var

	max=0
	case $morosidad in
		0)	max=0;;
		1) 	max=100;;
		2)	max=2000;;
		3)	max=5000;;
		4) 	max=10000;;
	esac

	var=`randomNum $max`
	var=`completar $var 10`
	deuda=$var



	var=`randomNum 2`
	if [ $var -eq 1 ];then
		zona3G=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		IUR=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		INT=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		ADSL=S
	fi

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		CABA=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		GBAOes=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		GBANor=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		Country=S
	fi

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		Delta=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		Rural=S
	fi

	var=`randomNum 2`
	if [ $var -eq 1 ];then
		Jub=S
	fi



	var=`randomNum 2`
	if [ $var -eq 1 ];then
		Res=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		CF=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		MO=S
	fi


	var=`randomNum 2`
	if [ $var -eq 1 ];then
		RI=S
	fi


	registro=$codCentral","$codCliente","$codArea","$zona3G","$nroLinea","$promedio","$morosidad","$deuda","$IUR","$INT","$ADSL","$CABA","$GBAOes","$GBANor","$Country","$Delta","$Rural","$Jub","$Res","$CF","$MO","$RI","$FechaCorte
	echo $registro
}

if [ $# -lt 1 ];then
	echo "indicar la cantidad de registros a crear"
	exit 1
fi

for (( i = 0 ; i < $1 ; i++ ))
do
	registro=`genRegistro $i`
	echo $registro
done

